﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace CafeOnline.Common {
    [Serializable]
    public struct Date : IComparable {
        #region IFields

        [DataMember]
        public DateTime Value;

        #endregion IFields
        #region IConstructors

        public Date(DateTime dt) {
            Value = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0, DateTimeKind.Utc);
        }

        #endregion IConstructors
        #region IMethods
        public static implicit operator DateTime(Date t) {
            return t.Value;
        }

        public static implicit operator Date(DateTime t) {
            return new Date(t);
        }

        public static bool operator <(Date t1, Date t2) {
            return t1.Value < t2.Value;
        }

        public static bool operator <=(Date t1, Date t2) {
            return t1.Value <= t2.Value;
        }

        public static bool operator >(Date t1, Date t2) {
            return t1.Value > t2.Value;
        }

        public static bool operator >=(Date t1, Date t2) {
            return t1.Value >= t2.Value;
        }

        public static bool operator ==(Date t1, Date t2) {
            return t1.Value == t2.Value;
        }

        public static bool operator !=(Date t1, Date t2) {
            return t1.Value != t2.Value;
        }

        public string ToString(string format) {
            return Value.ToString(format, CultureInfo.InvariantCulture);
        }

        public override bool Equals(object obj) {

            if (!(obj is Date)) {
                return false;
            }
            Date other = (Date)obj;

            return this == other;
        }

        public override int GetHashCode() {
            return Value.GetHashCode();
        }
        #endregion IMethods

        #region IComparable Members

        public int CompareTo(object obj) {
            if (!(obj is Date)) {
                return 1;
            }
            Date other = (Date)obj;
            return Value.CompareTo(other.Value);
        }

        #endregion IComparable Members
    }

    [Serializable]
    public struct FixedDateTime {
        #region IFields

        [DataMember]
        public DateTime m_date;

        #endregion IFields
        #region IConstructors

        public FixedDateTime(DateTime dt) {
            m_date = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond, DateTimeKind.Utc);
        }

        #endregion IConstructors
        #region IMethods

        public static implicit operator DateTime(FixedDateTime t) {
            return t.m_date;
        }

        public static implicit operator FixedDateTime(DateTime t) {
            return new FixedDateTime(t);
        }

        public static bool operator <(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date < t2.m_date;
        }

        public static bool operator <=(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date <= t2.m_date;
        }

        public static bool operator >(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date > t2.m_date;
        }

        public static bool operator >=(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date >= t2.m_date;
        }

        public static bool operator ==(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date == t2.m_date;
        }

        public static bool operator !=(FixedDateTime t1, FixedDateTime t2) {
            return t1.m_date != t2.m_date;
        }



        public override bool Equals(object obj) {

            if (!(obj is FixedDateTime)) {
                return false;
            }
            FixedDateTime other = (FixedDateTime)obj;

            return this == other;
        }

        public override int GetHashCode() {
            return m_date.GetHashCode();
        }

        public string ToString(string format) {
            return m_date.ToString(format, CultureInfo.InvariantCulture);
        }


        #endregion IMethods
    }
}
